package endcourseproject;

public class RobotStatusMsg extends RobotMsg {


	private static final int IntegerLenInBytes = Integer.SIZE / Byte.SIZE;   

	private static final int headingOffset = RobotMsg.msgDataOffset;   
	private static final int headingLen = IntegerLenInBytes;   

	private static final int angleOffset = headingOffset + headingLen;   
	private static final int angleLen = IntegerLenInBytes;   
	private static final int magnitudeOffset = angleOffset + angleLen;   
	private static final int magnitudeLen = IntegerLenInBytes;   

	private static final int flockIDOffset = magnitudeOffset + magnitudeLen;   
	private static final int flockIDLen = IntegerLenInBytes;   
	private static final int flockMembersOffset = flockIDOffset + flockIDLen;   
	private static final int flockMembersLen = IntegerLenInBytes;   
	private static final int flockStatusOffset = flockMembersOffset + flockMembersLen;   
	private static final int flockStatusLen = IntegerLenInBytes;   

	private static final int behavioursOffset = flockStatusOffset + flockStatusLen;   
	public static final int MaxBehaviorsInStatus = 5;   
	private static final int behaviourAngleOffset = 0;   
	private static final int behaviourAngleLen = IntegerLenInBytes;   
	private static final int behaviourMagnitudeOffset = IntegerLenInBytes;   
	private static final int behaviourMagnitudeLen = IntegerLenInBytes;   
	private static final int behaviourLen = behaviourAngleLen +behaviourMagnitudeLen;   

	
	public static final int MsgLen = behavioursOffset + (MaxBehaviorsInStatus*behaviourLen);  

	public RobotStatusMsg(RobotMsg msg)
	{
		super(msg.getRawMsg());
	}

	public RobotStatusMsg()
	{
		super(new byte[MsgLen]);
		byte[] msgd = this.getRawMsg();
        //initialize all bytes 2 0xFF
		for(int i= 0; i < msgd.length;i++)
		{
			msgd[i] = (byte) 0xFF;
		}
		this.setMsgType(StatusMsgType);
	}

	public int getHeading() {
		return Utils.CopyBytesToInt(this.getRawMsg(),headingOffset);
	}

	public void setHeading(int heading) {
		Utils.CopyIntToBytes(this.getRawMsg(),headingOffset, heading);
	}

	public int getAngle() {
		return Utils.CopyBytesToInt(this.getRawMsg(),angleOffset);
	}

	public void setAngle(int angle) {
		Utils.CopyIntToBytes(this.getRawMsg(),angleOffset, angle);
	}

	public int getMagnitude() {
		return Utils.CopyBytesToInt(this.getRawMsg(),magnitudeOffset);
	}

	public void setMagnitude(int magnitude) {
		Utils.CopyIntToBytes(this.getRawMsg(),magnitudeOffset, magnitude);
	}

	public int getFlockID() {
		return Utils.CopyBytesToInt(this.getRawMsg(),flockIDOffset);
	}

	public void setFlockID(int flockID) {
		Utils.CopyIntToBytes(this.getRawMsg(),flockIDOffset, flockID);
	}

	public int getFlockMembers() {
		return Utils.CopyBytesToInt(this.getRawMsg(),flockMembersOffset);
	}

	public void setFlockMembers(int flockMembers) {
		Utils.CopyIntToBytes(this.getRawMsg(),flockMembersOffset, flockMembers);
	}

	public int getFlockStatus() {
		return Utils.CopyBytesToInt(this.getRawMsg(),flockStatusOffset);
	}

	public void setFlockStatus(int flockStatus) {
		Utils.CopyIntToBytes(this.getRawMsg(),flockStatusOffset, flockStatus);
	}

	// the following are mostly for statistics 
	public int getBehaviourAngle(int index) {
		return Utils.CopyBytesToInt(this.getRawMsg(),behavioursOffset +(index*behaviourLen)+behaviourAngleOffset);
	}

	public void setBehaviourAngle(int index,int angle) {
		Utils.CopyIntToBytes(this.getRawMsg(),behavioursOffset +(index*behaviourLen)+behaviourAngleOffset, angle);
	}

	public int getBehaviourMagnitude(int index) {
		return Utils.CopyBytesToInt(this.getRawMsg(),behavioursOffset +(index*behaviourLen)+behaviourMagnitudeOffset);
	}

	public void setBehaviourMagnitude(int index, int magnitude) {
		Utils.CopyIntToBytes(this.getRawMsg(),behavioursOffset +(index*behaviourLen)+behaviourMagnitudeOffset, magnitude);
	}


}
